<?php

namespace app\api\controller;

use app\api\model\BigScreenModel;
use app\api\model\RealtimeRaceModel;
use app\BaseController;
use think\Exception;

class RealtimeRace extends BaseController
{
    public function index()
    {
        try {
            $limit = input('limit',2);
            //实例化模型
            $model = new RealtimeRaceModel();
            $data = $model
                ->with('raceType')
                ->field('id,name,type_id,group,start_time,as_time,status')
                ->limit($limit)
                ->select()
                ->toArray();
            //遍历时间戳为日期（到日）
            foreach ($data as $key => $value) {
                $data[$key]['start_time'] = date('Y-m-d', $value['start_time']);
                $data[$key]['as_time'] = date('Y-m-d', $value['as_time']);
            }
            $this->success('查询成功', $data);
        } catch (Exception $e) {
            $this->error('', $e->getMessage());
        }
    }
}